﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>坐标转换</title>
    <script src="../../lib/XiaoFuMap.js" type="text/javascript"></script>
    <script type="text/javascript">
        var map, control, svgLayer, transform;
        var pointA, pointB, pointC,  pointD;
        function load() {
            map = new XiaoFu.Map("#MapContainer");
            //var layer = new XiaoFu.GoogleCacheLayer("http://mt{0}.google.cn/vt/lyrs=m@180000000&hl=zh-CN&gl=cn&src=app&x={1}&y={2}&z={3}&s=Gal");
            var layer = new XiaoFu.BingCacheLayer("http://r{0}.tiles.ditu.live.com/tiles/r{1}.png?g=87");
            map.addLayer(layer);
            svgLayer = new XiaoFu.SVGLayers("line");
            map.addLayer(svgLayer);
            map.addEventListener("mousemove", function (eventType, data) {
                var center = map.getCenter();
                var extent = map.getCurrentExtent();
                var mouseGeo = data.mouseGeoPoint;
                var mousePoint = data.mousePoint;
                var sourceProj = new XiaoFu.Projection("EPSG:900913");
                //var sourceProj = new XiaoFu.Projection("EPSG:102100");
                var destProj = new XiaoFu.Projection("WGS84");
                var pointSource = mouseGeo;
                var pointDest = transform.transform(sourceProj, destProj, [pointSource]);

                var txt = ""
                + "<br/>地图中心 x-" + center.x + " y-" + center.y
                + "<br/>地图当前范围 minX-" + extent.minX + "minY-" + extent.minY + "maxX-" + extent.maxX + "maxY-" + extent.maxY
                + "<br/>鼠标点像素点 x-" + mousePoint.x + " y-" + mousePoint.y
                + "<br/>鼠标地理点EPSG:900913 x-" + mouseGeo.x + " y-" + mouseGeo.y
                + "<br/>鼠标地理点WGS84 x-" + pointDest[0].x + " y-" + pointDest[0].y;
                showMsg(txt);

            });
                
            
            control = new XiaoFu.Navigation();
            map.addControl(control);


            pointA = new XiaoFu.GeoPoint(-179, -85);
            pointB = new XiaoFu.GeoPoint(-179, 85);
            pointC = new XiaoFu.GeoPoint(179, 85);
            pointD = new XiaoFu.GeoPoint(179, -85);
            var sourceProj = new XiaoFu.Projection("WGS84");
            var destProj = new XiaoFu.Projection("EPSG:900913");
            //var destProj = new XiaoFu.Projection("EPSG:102100");
            var transform = new XiaoFu.Transform();
            var pointDest = transform.transform(sourceProj, destProj, [pointA, pointB, pointC, pointD, pointA]);


            var line_db = new XiaoFu.SVG_Line(0, "line0", pointDest);
            line_db.stroke = "yellow";
            line_db.stroke_width = "5";
            svgLayer.addChild(line_db);
        }
        function showMsg(_msg) {
            $("#msg").html(_msg);
        }
       
    </script>
</head>
<body onload="load()">
    <div id="MapContainer" style="z-index: 10000; border: 1px solid blue; position: relative;
        width: 1000px; height: 500px;">
    </div>  
    <div id="msg">
    </div>
</body>
</html>
